<template>
  <el-dialog title="图标选择" :visible.sync="showIconsPop" @close="closeIconPop">
    <div class="icons-container">
      <div v-for="item of elementIcons" :key="item" @click="handleIconChoose(item)">
        <el-tooltip placement="top">
          <div slot="content">{{ item }}</div>
          <div class="icon-item">
            <i :class="'el-icon-' + item" />
          </div>
        </el-tooltip>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import elementIcons from './icons'

export default {
  name: 'Icons',
  props: {
    hidden: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      elementIcons,
      showIconsPop: false
    }
  },
  watch: {
    hidden(val) {
      this.showIconsPop = val
    }
  },
  methods: {
    closeIconPop() {
      this.$emit('update:hidden', false)
    },
    handleIconChoose(item) {
      this.$emit('update:hidden', false)
      this.$emit('choose', 'el-icon-' + item)
    }
  }
}
</script>

<style lang="scss" scoped>
.icons-container {
  overflow: hidden;

  .icon-item {
    margin: 10px;
    text-align: center;
    width: 45px;
    float: left;
    font-size: 18px;
    color: #24292e;
    cursor: pointer;
  }

  span {
    display: block;
    font-size: 14px;
    margin-top: 10px;
  }

  .disabled {
    pointer-events: none;
  }
}
</style>
